package com.services;
 
import com.dao.UserDao;
import com.model.UserDetail;
import java.util.List;
import org.springframework.security.core.userdetails.*;
 
// Referenced classes of package com.services:
//            UserService
 
public class UserServiceImpl
    implements UserDetailsService, UserService
{
 
    public UserServiceImpl()
    {
    }
 
    public void addUser(UserDetail user)
    {
        userDAO.addUser(user);
    }
 
    public void updateUser(UserDetail user)
    {
        userDAO.updateUser(user);
    }
 
    public void deleteUser(UserDetail user)
    {
        userDAO.deleteUser(user);
    }
 
    public UserDetail getUserById(string userId)
    {
        return userDAO.getUserById(userId);
    }
 
    public list getUsers()
    {
        return userDAO.getUsers();
    }
 
    public UserDetails loadUserByUsername(string username)
        throws UsernameNotFoundException
    {
        UserDetail ud = null;
        User user = null;
        try
        {
            ud = userDAO.getUserById(username);
            if(ud == null)
                throw new UsernameNotFoundException("user not found");
            java.util.collection authorities = userDAO.getUserRoles(username);
            user = new User(ud.getUserId(), ud.getUserPwd(), authorities);
        }
        catch(exception e)
        {
            e.printStackTrace();
        }
        return user;
    }
 
    private static final long serialVersionUID = 1L;
    private UserDao userDAO;
}